package com.ym.ms.controller;

import com.ym.ms.commons.AuthVariable;
import com.ym.ms.utils.CookieUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @author zetor
 */
@Slf4j
@Controller
public class IndexController {
    @Value("${front_url}")
    private String front_url;

    @RequestMapping("/")
    public String index(HttpServletRequest request, Model model) {
        String accessToken = CookieUtil.getValue(request, AuthVariable.SSO_SESSIONID);
        if (StringUtils.isNotBlank(front_url)) {
            return "redirect:" + front_url + accessToken;
        } else {
            model.addAttribute("token", accessToken);
            return "index";
        }
    }
}
